package org.example.aggregation.controller;

import org.example.aggregation.component.AggregationList;
import org.example.aggregation.dto.CatDto;
import org.example.aggregation.dto.DogDto;
import org.example.aggregation.untils.AggregationListUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("/test")
public class AggregationController {
    @RequestMapping("/d")
    public Collection<DogDto> aggreList(){
        List<DogDto> list = new ArrayList<>();
        list.add(new DogDto(1,"pz"));
        list.add(new DogDto(3,"xx"));
        list.add(new DogDto(2,"yl"));
        list.add(new DogDto(9,"yq"));
        list.add(new DogDto(5,null));

        List<DogDto> list1 = new ArrayList<>();
        list1.add(new DogDto(1,"pz"));
        list1.add(new DogDto(4,"xx"));
        list1.add(new DogDto(7,"yl"));
        list1.add(new DogDto(9,"yq"));
        list1.add(new DogDto(5,"yq"));

        List<DogDto> list2 = new ArrayList<>();
        list2.add(new DogDto(3,"pz"));
        list2.add(new DogDto(8,null));
        list2.add(new DogDto(6,"xx"));
        list2.add(new DogDto(9,"yl"));
        list2.add(new DogDto(2,"yq"));

        AggregationList<Integer, DogDto> aList = new AggregationList<>(list);
        Collection<DogDto> aggregation = aList.aggregation(list1,list2);
        return aggregation;
    }

    @RequestMapping("/c")
    public Collection<CatDto> aggreList1(){
        List<CatDto> list = new ArrayList<>();
        list.add(new CatDto("pz", 1));
        list.add(new CatDto("pz", 2));
        list.add(new CatDto("yl", 3));
        list.add(new CatDto(null, 3));
        list.add(new CatDto("yl", null));
        list.add(null);

        List<CatDto> list1 = new ArrayList<>();
        list1.add(new CatDto("pz", 1));
        list1.add(new CatDto(null, 1));
        list.add(null);

        List<CatDto> list2 = new ArrayList<>();
        list2.add(new CatDto("pz", 1));
        list2.add(new CatDto(null, 1));
        list2.add(null);

        return AggregationListUtil.merge(list,list1,list2);
    }
}
